package cn.yunhe.main;

import cn.yunhe.bean.Emp;
import cn.yunhe.dao.IEmpDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Emtry {

    public static void main(String[] args) throws IOException {
        //读取mybatis的配置文件
        InputStream inputStream = Resources.getResourceAsStream("sqlMapconfig.xml");
        //创建factory对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);
        //创建SqlSession对象
        SqlSession sqlSession = factory.openSession();

        IEmpDao empDao = sqlSession.getMapper(IEmpDao.class);
        //执行功能
        List<Emp> empList = empDao.queryEmps();
        System.out.println(empList);
        //关闭sqlSession对象
        sqlSession.close();
    }
}
